package com.dream.xiaobo.service.impl;

import com.dream.xiaobo.dao.impl.AddressDaoImpl;
import com.dream.xiaobo.entity.Address;
import com.dream.xiaobo.service.AddressService;

import java.sql.SQLException;
import java.util.List;

/**
 * @author xiaobo
 * @date 2021/9/2 - 8:09
 */
public class AddressServiceImpl implements AddressService {

    //实例化Address实例化对象
    private AddressDaoImpl addressDao = new AddressDaoImpl();

    /**
     * 查看用户地址信息业务逻辑实现方法
     * @param uId
     * @return
     * @throws SQLException
     */
    @Override
    public List<Address> findAddressByUId(Integer uId) throws SQLException {

        //调用dao实现方法
        List<Address> list = addressDao.selectAddressByUId(uId);

        //返回查询结果
        return list;
    }

    /**
     * 插入地址信息业务逻辑实现方法
     * @param address
     * @throws SQLException
     */
    @Override
    public void insertAddress(Address address) throws SQLException {

        //调用dao实现方法
        addressDao.insertAddress(address);

    }

    /**
     * 删除地址信息逻辑实现方法
     * @param aId
     * @throws SQLException
     */
    @Override
    public void deleteAddress(String aId) throws SQLException {
        //调用dao实现方法
        addressDao.deleteAddressByAId(aId);
    }

    /**
     * 设置默认地址逻辑实现方法
     * @param aId
     * @throws SQLException
     */
    @Override
    public void setDefault(String aId) throws SQLException {

        //调用dao实现方法
        addressDao.updateAddressToByAId(aId);
        //调用dao实现方法
        addressDao.updateAddressNOTByAId(aId);

    }

    /**
     * 更新地址逻辑实现方法
     * @param address
     * @throws SQLException
     */
    @Override
    public void updateAddress(Address address) throws SQLException {

        //调用dao实现方法
        addressDao.updateAddress(address);
    }
}
